package collect.taobao.dao.impl;
import collect.taobao.dao.ImageStreamDao;
import collect.taobao.bean.ImageStreamBean;


import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class ImageStreamDaoImpl extends HibernateDaoSupport implements ImageStreamDao{
	public int save(ImageStreamBean imageStreamBean) {
		int i=0;
		Session session =null;
		try{
			session = this.getSession();
	        Transaction trans = session.beginTransaction();
			this.getHibernateTemplate().save(imageStreamBean);
			trans.commit();   
			i=1;
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			if(session!=null)session.close();
		}
		return i;
	}
	public int delete(ImageStreamBean imageStreamBean) {
		int i=0;
		Session session =null;
		try{
			session = this.getSession();
	        Transaction trans = session.beginTransaction();
			this.getHibernateTemplate().delete(imageStreamBean);
			trans.commit();   
			i=1;
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			if(session!=null)session.close();
		}
		return i;
	}

	public int update(ImageStreamBean imageStreamBean) {
		int i=0;
		Session session =null;
		try{
			session = this.getSession();
	        Transaction trans = session.beginTransaction();
			this.getHibernateTemplate().update(imageStreamBean);
			trans.commit();   
			i=1;
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			if(session!=null)session.close();
		}
		return i;
	}
	
	public List queryList() {
		return this.getHibernateTemplate().loadAll(ImageStreamBean.class);
	}

	public ImageStreamBean query(String id) {
		Session session =null;
		ImageStreamBean  imageStreamBean = null;
		try{
			session = this.getSession();
			imageStreamBean = (ImageStreamBean)session.load(ImageStreamBean.class, new Integer(id)); 
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			if(session!=null)session.close();
		}
		return imageStreamBean;
	}
}
